#!/usr/bin/env python3
"""
图片识别与对比工具入口文件 - 调用src/app.py中的main函数
"""
import sys
import os
import traceback
import asyncio
import qasync  # 确保安装了qasync库

# 添加项目根目录到路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

try:
    from PySide6.QtWidgets import QApplication
    from src.views.main_window import MainWindowView
    from src.models.recognition_model import RecognitionModel
    from src.controllers.recognition_controller import RecognitionController
    from src.utils.style_manager import StyleManager
    from config.settings import UI
    
    if __name__ == "__main__":
        # 创建应用程序实例
        app = QApplication(sys.argv)
        
        # 加载和应用全局样式
        style_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), UI["style_file"])
        StyleManager.apply_global_style(app, style_file)
        
        # 创建 MVC 组件
        model = RecognitionModel()
        view = MainWindowView()
        
        # 创建控制器并明确连接信号
        controller = RecognitionController(model, view)
        
        # 显示主窗口
        view.show()
        
        # 设置异步事件循环
        loop = qasync.QEventLoop(app)
        asyncio.set_event_loop(loop)
        
        # 进入应用程序主循环
        with loop:
            loop.run_forever()
            sys.exit(0)
except Exception as e:
    print("发生错误:", str(e))
    traceback.print_exc() 